{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "from data import to_data_loader, load_data\n",
    "from models import (TextCNN, CNN_BiLSTM, AttnCNN, RNN)\n",
    "from sklearn.model_selection import KFold\n",
    "from train import train\n",
    "import gc\n",
    "from common.configs.path import paths\n",
    "from common.configs.tools import reversed_label, set_seed, predict, weights_init_uniform_rule\n",
    "import torch.optim as optim\n",
    "import torch.nn as nn\n",
    "import torch\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import random\n",
    "from tqdm import tqdm\n",
    "from argparse import ArgumentParser\n",
    "\n",
    "import warnings"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "train_texts, input_ids, test_texts, labels, word2idx, embeddings = load_data(\n",
    "        1, max_len=64)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "100%|██████████| 3456/3456 [00:00<00:00, 115265.15it/s]"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "(14009, 130)\n",
      "Loading pretrained vectors...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "model = torch.load(paths['model_path'] + r'TextCNN2d_[f1]0734_[ep]80_[gram]1.model')"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "output = pd.DataFrame(columns=['id', 'label'])\n",
    "\n",
    "for i, text in tqdm(enumerate(test_texts)):\n",
    "    label = reversed_label[predict(\n",
    "        text, model=model, word2idx=word2idx).numpy()[0]]\n",
    "    output.loc[i] = [i, label]\n",
    "output.to_csv('result_{}_[f1]{}_[ep]{}_[lr]{}_[gram]{}_[Emd]{}.csv'.format(\"TextCNN2d\",\n",
    "                                                                            \"0734\",\n",
    "                                                                            \"001\",\n",
    "                                                                            80,\n",
    "                                                                            1,\n",
    "                                                                            \"True\"), index=False)\n"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "6004it [00:36, 166.68it/s]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [],
   "outputs": [],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.8.8",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.8 64-bit (conda)"
  },
  "interpreter": {
   "hash": "1b89aa55be347d0b8cc51b3a166e8002614a385bd8cff32165269c80e70c12a7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}